package controllers;

import helpers.CookieHelper;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MessageLoginSubmitServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		String confirm = (String) request.getParameter("confirm");
		
		if (confirm != null && !confirm.isEmpty()) {
			if (confirm.equalsIgnoreCase("y")) {
				CookieHelper.setCookie(response, "isLoggin", "no");
				response.sendRedirect("/login");
				return;
			} else {
				CookieHelper.setCookie(response, "isLoggin", "no");
				response.sendRedirect("/submit-article");
				return;
			}
		}
		
		try {
			request.getRequestDispatcher("/pages/message_login_submit.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
}
